package com.example.demo.Controller;

import org.apache.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.github.kevinsawicki.http.HttpRequest;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class Adapt {
    @RequestMapping("/sendGet")
    public String sendGet(String url){
        Map<String, String> data = new HashMap<String, String>();
//       wx677864619bc5634c

        data.put("image_url", url);
        data.put("appkey","a36c3db0a0779977b4fb227ff85577ab");
//       dcf5b32d8fb1a81d6312bc1d52092b9e
        String response = HttpRequest.get("https://way.jd.com/JDAI/cvImage?"+"image_url="+url+"&appkey=a36c3db0a0779977b4fb227ff85577ab").body();
        //JSONObject obj= JSON.parseObject(response);//将json字符串转换为json对
        return response.toString();
    }
    @RequestMapping(value = "/sendPost")
    public String sendPost(String message){

        Map<String,String> param = new HashMap<>();
        param.put("data","4bf5ff18b9140a58");
          String a=OkHttpUtil.postJsonParamsHeader("https://api.yonyoucloud.com/apis/dst/WordsFilter/check",message);
//        RestTemplate resetTemplate = new RestTemplate();
//        HttpHeaders headers = new HttpHeaders();
//        MultiValueMap<String, String> requestMap= new LinkedMultiValueMap<String, String>();
//        requestMap.add("Content-Type", "text/plain");
//        requestMap.add("Authorization", "apicode");
//        requestMap.add("apicode", "efeb79b9ce8a4aa98b581ecb519f54d4");
//        HttpEntity<String> requestParam = new HttpEntity<>( requestMap, headers);
//        String responseAsString = resetTemplate.postForObject("https://api.yonyoucloud.com/apis/dst/WordsFilter/check",requestParam,String.class);
//       return responseAsString;
    return  a;
    }
}
